<template>
	
	<div class="height-full center-item-box">
		<div>
			<div style="font-size: 50px; margin: 0 auto; text-align: center;">{{username}}</div>

			<t-button v-show="buttonReady" @click="scan" theme="primary" style="width: 150px; height: 150px" shape="circle">
				<t-icon name="qrcode" style="font-size: 90px;" />
			</t-button>
		</div>
	</div>
	<t-tab-bar v-model="activeValue"  @change="menuSelect" shape="round" theme="tag" :split="false">
	    <t-tab-bar-item v-for="item in list" :key="item.value" :value="item.value">
	      <template #icon>
	        <t-icon :name="item.icon" />
	      </template>
	    </t-tab-bar-item>
	</t-tab-bar>
</template>
<script>

	import wx from 'weixin-js-sdk'
	export default {
		data() {
			return {
				activeValue: 'home',
				username: '',
				list: [
				  { value: 'home', label: '首页', icon: 'home' },
				  { value: 'user', label: '我的', icon: 'user' },
				],
				buttonReady: false,
			}
		},
		watch:{
			
		},
		mounted() {
			var user_info  = this.$TOOL.data.get("USER_INFO")
			if (user_info) {
				this.username = user_info.userName
			}

			wx.ready(() => {
				this.buttonReady = true
			})

			this.wxConfig()
		},
		methods: {
			menuSelect(e) {
				console.log(e);
				if (e == 'user') {
					// 跳转个人中心
					this.$router.replace({
						path: '/user'
					})
				} 
			},
			scan() {

				wx.scanQRCode({
					needResult: 1,
					scanType: ['qrCode'],
					success: (res) => {
						var result = this.parseUrlParams(res.resultStr)
						this.$router.replace({
							path: '/task',
							query: {patch: result.patch}
						})
					}
				})
			
			},

			parseUrlParams(url) {
			  const reg = /(\w+)=(\w+)/g;
			  const params = {};
			  let match;
			  while ((match = reg.exec(url))) {
			    params[match[1]] = match[2];
			  }
			  return params;
			},
			async wxConfig() {
				var reqData = {
					uri: window.location.href
				}
				var res = await this.$API.salary.wxconfig.get(reqData);
				if (res.code == 200) {
					wx.config({
						debug: false,
						appId: res.data.appId,
						timestamp: res.data.timestamp,
						nonceStr: res.data.noncestr,
						signature: res.data.signature,
						jsApiList: ["scanQRCode"] 
					})

				}
			}
		}
	}
</script>
<style type="text/css">
	.el-footer {padding: 0px}
	.el-menu-item {width: 100%}
</style>